from django.db import models

class Author(models.Model):
	name = models.CharField(maxlength=50)
	website = models.URLField(null=True, blank=True)
	
	def __unicode__(self):
		return self.name
	
	class Admin:
		list_display = ('name',)
		ordering = ('-name',)
		search_fields = ('name',)

class UserProfile(models.Model):
	name = models.CharField(maxlength=100, unique=True)
	address = models.TextField(null=True, blank=True)
	
	def __unicode__(self):
		return self.name
	
	class Admin:
		list_display = ('name',)
		ordering = ('-name',)
		search_fields = ('name',)

class Library(models.Model):
	name = models.CharField(maxlength=100)
	address = models.TextField(null=True, blank=True)
	
	def __unicode__(self):
		return self.name
	
	class Admin:
		list_display = ('name',)
		ordering = ('-name',)
		search_fields = ('name',)

class Book(models.Model):
	library = models.ForeignKey(Library)
	title = models.CharField(maxlength=100)
	about = models.TextField(null=True, blank=True)
	authors = models.ManyToManyField(Author)
	publication_date = models.DateField(null=True, blank=True)
	who_borrowed = models.ForeignKey(UserProfile, null=True, blank=True)
	
	def __unicode__(self):
		return self.title
	
	class Admin:
		list_display = ('title', 'library', 'who_borrowed')
		list_filter = ('library',)
		ordering = ('-title',)
		search_fields = ('title',)